package com.liutaw.nanjingair.views.viewcomponent.banner;

import android.content.Context;
import android.view.View;
import android.widget.TextView;
import android.widget.ViewSwitcher;

import java.util.List;

/**
 * Created by liutao on 15/11/19.
 */
public class MyViewFactory implements ViewSwitcher.ViewFactory {
    private int currentIndex;
    private List<TextView> lists;
    private Context mContext;
    private ViewSwitcher viewSwitcher;

    public MyViewFactory(Context context, List<TextView> lists, ViewSwitcher viewSwitcher) {
        this.lists = lists;
        currentIndex = 0;
        this.mContext = context;
        this.viewSwitcher = viewSwitcher;
    }

    @Override
    public View makeView() {
        if (this.lists == null || this.lists.size() == 0) {
            return new View(mContext);
        }

        TextView current = lists.get(currentIndex);
        currentIndex++;
        if (currentIndex == lists.size()) {
            currentIndex = 0;
        }

        return current;
    }

    public List<TextView> getLists() {
        return lists;
    }

    public void setLists(List<TextView> lists) {
        currentIndex = 0;
        this.lists = lists;
    }

    public void moveToNext() {
        viewSwitcher.removeAllViews();
        viewSwitcher.addView(makeView());
    }
}
